package com.github.lee.unsplash.utils.ba

import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import androidx.databinding.BindingAdapter

@BindingAdapter("text_changed")
fun textChanged(v: EditText, block: ((String?) -> Unit)?) {
    if (null != block) {

        v.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

            override fun afterTextChanged(s: Editable?) {
                block.invoke(s?.toString())
            }
        })
    }
}